package ch.fhnw.kosmonauten.client.core;

/**
 * Diese Klasse modifiziert das Hexagram.
 * 
 * @author Fabian Siegrist
 * @author Oliver Freiermuth
 * @author Mikhail Onoufrienko
 * @author Risto Milani
 * @version $Revision: 95 $
 *          File name: $HeadURL: https://iching-kosmonauten.googlecode.com/svn/I-Ching/src/ch/fhnw/kosmonauten/server/net/dto/Transformation.java $
 *          Last modified:$Date: 2013-05-24 15:20:57 +0200 (Fri, 24 May 2013) $
 *          Last modified by: $Author: molotok.mihon@gmail.com $
 */

// class definition
public class HexagramModification {

	// constructors
	public HexagramModification() {

	}

	// methods
	/**
	 * @param situation
	 * @return
	 */
	public static int[] getPerspective(int[] situation) {
		int[] perspective = new int[6];
		if (situation.length == 6) {
			for (int i = 0; i < situation.length; i++) {
				switch (situation[i]) {
				case 6:
					perspective[i] = 7;
					break;
				case 7:
					perspective[i] = 7;
					break;
				case 8:
					perspective[i] = 8;
					break;
				case 9:
					perspective[i] = 8;
					break;
				default:
					return null;
				}
			}
			return perspective;
		} else
			return null;
	}

	/**
	 * @param situation
	 * @return
	 */
	public static int[] getBinaryCode(int[] situation) {
		int[] binaryCode = new int[6];
		if (situation.length == 6) {
			for (int i = 0; i < situation.length; i++) {
				switch (situation[i]) {
				case 6:
					binaryCode[i] = 0;
					break;
				case 7:
					binaryCode[i] = 1;
					break;
				case 8:
					binaryCode[i] = 0;
					break;
				case 9:
					binaryCode[i] = 1;
					break;
				default:
					return null;
				}
			}
			return binaryCode;
		} else
			return null;
	}
	
	public static int[] getHexagramCode(int[] binarycode) {
		int[] hexagramCode = new int[6];
		if (binarycode.length == 6) {
			for (int i = 0; i < binarycode.length; i++) {
				switch (binarycode[i]) {
				case 0:
					hexagramCode[i] = 8;
					break;
				case 1:
					hexagramCode[i] = 7;
					break;
				default:
					return null;
				}
			}
			return hexagramCode;
		} else
			return null;
	}

}
